package com.cloud.bssp.admin.wanda.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bssp.admin.wanda.dto.EmployeeDTO;
import com.cloud.bssp.admin.wanda.entity.EmployeeDO;
import com.cloud.bssp.util.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 员工表
 * Create Date: 2021-07-08T15:36:33.901
 * Modified By：<br>
 * Modified Date：<br>
 * Why & What is modified：<br>
 *
 * @author weirx
 * @version 1.0
 */
@Component
public class EmployeeDoConvert {

    /**
     * DtoToDo
     *
     * @param employeeDTO
     * @return
     */
    public static EmployeeDO dtoToDo(EmployeeDTO employeeDTO) {
            EmployeeDO employeeDO = new EmployeeDO();
        BeanCopierUtil.copy(employeeDTO, employeeDO);
        return employeeDO;
    }

    /**
     * DoToDto
     *
     * @param employeeDO
     * @return
     */
    public static EmployeeDTO doToDto(EmployeeDO employeeDO) {
            EmployeeDTO employeeDTO = new EmployeeDTO();
        BeanCopierUtil.copy(employeeDO, employeeDTO);
        return employeeDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<EmployeeDTO> pageConvert(Page<EmployeeDO> pageDO) {
        List<EmployeeDTO> list = listConvert(pageDO.getRecords());
        Page<EmployeeDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<EmployeeDTO> listConvert(List<EmployeeDO> listDO) {
        List<EmployeeDTO> list = new ArrayList<>();
            EmployeeDTO employeeDTO;
        for (EmployeeDO employeeDO : listDO) {
                employeeDTO = new EmployeeDTO();
            BeanCopierUtil.copy(employeeDO, employeeDTO);
            list.add(employeeDTO);
        }
        return list;
    }
}